package com.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.Comment;
import com.service.CommentService;

@Controller
public class CommentController {

	@Resource
	private CommentService cs;
	@Resource
	private HttpServletRequest request;
	@RequestMapping("Comment")
	public String finComment(Model model){
		String pages=request.getParameter("page");
		int page=Integer.parseInt(pages);
		int sum=cs.getSum();
		if(page>=sum){
			page=sum;
		}
		model.addAttribute("page", page);
		model.addAttribute("sum", sum);
		List<Comment> list=cs.getComment(page);
		model.addAttribute("list", list);
		return "/comment.jsp";
	}
	@RequestMapping("addComment")
	public String addComment(Model model,Comment comment){
		System.out.println(""+comment);
		cs.addComment(comment);
		return "/Comment?page=1";
	}
}
